package com.yjzx.care.base;

import com.yjzx.care.MyInterface;

import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author yjzx
 * @date 2023/12/25
 * @description 判断基类
 */
public abstract class BaseElement implements MyInterface {
    private final AtomicBoolean whether = new AtomicBoolean(true);

    /**
     * 进行判断后返回的对象
     */
    public interface Else {

    }

    protected BaseElement() {
    }

    public boolean isWhether() {
        return whether.get();
    }

    /**
     * 校验是否需要执行
     *
     * @param whether 判断的是否执行
     * @return
     */
    protected synchronized boolean exist(boolean whether) {
        boolean b = this.whether.get();
        this.whether.set(!(whether = b && whether) && b);
        return whether;
    }

}
